namespace SimpleWebServices.Models
{
    using System.Xml.XPath;
    using SimpleWebServices;
    using SimpleWebServices.Security.Cryptography;
    using SimpleWebServices.Web;
    using Xunit;

    public sealed class GeographyFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<Geography>()
                .DerivesFrom<Resource>()
                .IsConcreteClass()
                .IsUnsealed()
                .HasDefaultConstructor()
                .XmlRoot("geography")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            Geography actual = "<geography title='United Kingdom' />".Deserialize<Geography>();

            Assert.NotNull(actual);

            Assert.Equal<string>("United Kingdom", actual.Title);
        }

        [Fact]
        public void deserializeEmpty()
        {
            Geography actual = "<geography />".Deserialize<Geography>();

            Assert.NotNull(actual);

            Assert.Null(actual.Title);
        }

        [Fact]
        public void serialize()
        {
            Geography obj = new Geography
            {
                Title = "United Kingdom"
            };

            XPathNavigator navigator = obj.Serialize().CreateNavigator();

            Assert.True((bool)navigator.Evaluate("1=count(/geography[@title='United Kingdom'])"));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new Geography());
        }

        [Fact]
        public void prop_Entity()
        {
            Assert.True(new PropertyExpectations(typeof(Geography).GetProperty("Entity"))
                .XmlIgnore()
                .TypeIs<string>()
                .DefaultValueIsNotNull()
                .Result);
        }

        [Fact]
        public void prop_Entity_get()
        {
            Geography obj = new Geography
            {
                Title = "United Kingdom"
            };

            string expected = "ifnJ9Im+KoPPV+U7kZfSiA==";
            string actual = MD5Hash.Compute(obj.Entity);

            Assert.Equal<string>(expected, actual);
        }

        [Fact]
        public void prop_Entity_getEmpty()
        {
            string expected = string.Empty;
            string actual = new Geography().Entity;

            Assert.Equal<string>(expected, actual);
        }
    }
}